<!-- 医疗器械生产备案凭证 -->
<template>
  <div class="medical-device-production-record-certificate-card">
    <div class="upload-card-corver" v-if="!edit">
      <upload-card
        v-on="$listeners"
        v-bind="$attrs"
        :isClick="!edit"
        :defaultBgImg="bgImgUrl"
        @click="onClick"
      />
    </div>
    <licence-card
      v-else
      :data='data' 
      v-on='$listeners' 
      :type='type'
      @update='updateCorrespondingLicence' 
      @delete='deleteCorrespondingLicence' 
      @detail='detailCorrespondingLicence'
    ><span>医疗器械生产备案凭证</span>
    </licence-card>
    <medical-device-production-record-certificate-form 
      :adminInfoDataForm='adminForm'
      :edit='formEdit'
      :form='data'
      @refuse='handleClose'
      @submit='saveResult' 
      :before-close="handleClose" 
      title="新增医疗器械生产备案凭证" 
      :visible.sync="dialogVisible"
    >
      <template #header>
        <h4 class="dialog-class-name">（以下内容与证照内容保持一致）</h4>
      </template>
    </medical-device-production-record-certificate-form>
  </div>
</template>
<script>
import uploadCard from '@/moduleComponents/licence/common/uploadCard'
import licenceCard from '@/moduleComponents/licence/common/licenceCard'
import medicalDeviceProductionRecordCertificateForm from '@/moduleComponents/licence/form/medicalDeviceProductionRecordCertificateForm'

export default {
  name: 'medicalDeviceProductionRecordCertificateCard',
  components: {
    uploadCard,
    licenceCard,
    medicalDeviceProductionRecordCertificateForm
  },
  props: {
    data:{
      default:() => {},
      type: Object
    },
    adminInfo: {
      default: () => {},
      type: Object
    },
    type: {
      default: 'create',
      type: String
    }
  },
  watch:{
    data:{
      handler(nv,ov) {
        if(nv && nv.id) {
          this.edit = true
        }
      },
      deep: true
    },
    adminInfo:{
      handler(nv,ov) {
        this.adminForm = nv
      },
      deep: true
    }
  },
  data() {
    return {
      bgImgUrl:require('./img/pc-ylqxscbapz-bg.png'),
      dialogVisible: false,
      edit: false, // 代表着当前整个单据的编辑状态
      formEdit: false, // 代表着证照表单的编辑状态
      adminForm: {}, 
    }
  },
  methods: {
    updateCorrespondingLicence(data) {
      this.dialogVisible = true
      this.formEdit = false
    },
    detailCorrespondingLicence(data) {
      this.dialogVisible = true
      this.formEdit = true
    },
    deleteCorrespondingLicence() {
      this.edit = false
      this.formEdit = false
      this.$emit('getBusinessLicenceForm', {
        manufactureScope:'', // 生产范围
        companyName:'', // 企业名称
        certificateCode:'', // 备案编号
        dwellPlace:'', // 住所
        manufactureAddress:'', // 生产地址 
        personInCharge:'', // 企业负责人
        president:'', // 法定代表人
        recordDept:'', // 备案部门
        recordTime:'', // 备案日期
        url:'' // 证件图片地址
      })
    },
    onClick() {
      if(!(this.type === "check")) {
        this.dialogVisible = true
      }
    },
    handleClose() {
      this.dialogVisible = false
    },
    saveResult(data) {
      this.$emit('getBusinessLicenceForm', data)
      this.edit = true
      this.dialogVisible = false
    }
  }
}
</script>
<style lang="less">
.medical-device-production-record-certificate-card {
  .upload-card-corver{
    width: 380px;
    height: 242px;
  }
}
</style>
